﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HCFramework.API.LINQ;

namespace M
{
    public class Template
    {
        public static string MergeFeedBack(string template, FeedBack f)
        {
            template = MergeCurrentDomain(template);

            template = Merge(template, "FeedBackID", f.FeedBackID.ToString());
            template = Merge(template, "Subject", f.Subject);
            template = Merge(template, "Content", f.Content);
            template = Merge(template, "Name", f.Name);
            template = Merge(template, "Email", f.Email);

            return template;
        }

        public static string MergeProduct(string template, Product p)
        {
            template = MergeCurrentDomain(template);

            template = Merge(template, "ProductID", p.ProductID + "");
            template = Merge(template, "ProductCode", p.ProductCode);
            template = Merge(template, "ProductName", p.ProductName);
            template = Merge(template, "Description", p.Description);
            template = Merge(template, "DateTimeInsert", p.DateTimeInsert.ToShortDateString());
            template = Merge(template, "Price", p.Price.ToString("N0"));
            template = Merge(template, "CurrencyCode", p.CurrencyCode);
            template = Merge(template, "LastEditDate", p.LastEditDate.ToShortDateString());
            template = Merge(template, "MainImageUrl", C.ProductImageController.GetMainImageURL(p));

            return template;
        }

        public static string MergeOrder_Product(string template, Order_Product op)
        {
            template = MergeCurrentDomain(template);

            template = Merge(template, "CurrencyCode", op.CurrencyCode);
            template = Merge(template, "ID", op.ID + "");
            template = Merge(template, "OrderID", op.OrderID + "");
            template = Merge(template, "Price", op.Price.ToString("N0"));
            template = Merge(template, "ProductID", op.ProductID + "");
            template = Merge(template, "Quantity", op.Quantity + "");

            return template;
        }

        public static string MergeOrderContact(string template, OrderContact oc)
        {
            template = MergeCurrentDomain(template);

            template = Merge(template, "Address", oc.Address);
            template = Merge(template, "Email", oc.Email);
            template = Merge(template, "Name", oc.Name);
            template = Merge(template, "OrderContactID", oc.OrderContactID + "");
            template = Merge(template, "PhoneNumber", oc.PhoneNumber);

            return template;
        }

        public static string MergeOrder(string template, Order order)
        {
            template = MergeCurrentDomain(template);

            template = Merge(template, "CreatedDate", order.CreatedDate.ToShortDateString());
            template = Merge(template, "DeliveryType", C.OrderController.GetDeliveryName(order.DeliveryType));
            template = Merge(template, "Identity", order.Identity + "");
            template = Merge(template, "TotalPrice", C.OrderController.GetTotalPrice(order.OrderID).ToString("N0"));
            template = Merge(template, "OrderID", order.OrderID.ToString("D7"));
            template = Merge(template, "OrderCode", C.OrderController.GetOrderCode(order.OrderID));
            template = Merge(template, "PaymentMethod", C.OrderController.GetPaymentMethodName(order.PaymentMethod));
            template = Merge(template, "Status", C.OrderController.GetStatusName(order.Status));
            
            return template;
        }

        public static string MergeUser(string template, User user)
        {
            template = MergeCurrentDomain(template);

            template = Merge(template, "DateCreated", user.DateCreated.ToShortDateString());
            template = Merge(template, "Email", user.Email);
            template = Merge(template, "FirstName", user.FirstName);
            template = Merge(template, "LastName", user.LastName);
            template = Merge(template, "Password", user.Password);
            template = Merge(template, "Username", user.Username);

            return template;
        }

        public static string MergeCurrentDomain(string template)
        {
            template = Merge(template, "CurrentDomain", M.Common.GetRootAddress());
            
            return template;
        }

        public static string Merge(string template, string name, string value)
        {
            template = template.Replace("{" + name + "}", value);
            
            return template;
        }
    }
}